package cn.shuto.liferay.plugin.chart.portlet.view;

import java.io.IOException;
import java.io.PrintWriter;

import javax.portlet.PortletException;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import cn.shuto.liferay.plugin.chart.service.util.VelocityTemplateUtil;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * Portlet implementation class ChartViewPortlet
 */
public class ChartViewPortlet extends MVCPortlet {
 
	@Override
	public void serveResource(ResourceRequest resourceRequest,
			ResourceResponse resourceResponse) throws IOException,
			PortletException {
		//获取配置的图表的ID
		long optionId = ParamUtil.getLong(resourceRequest, "optionId");
		String namespace = ParamUtil.getString(resourceRequest, "namespace");
		String chart_view_theme = ParamUtil.getString(resourceRequest, "chart_view_theme");
		String chart_height = ParamUtil.getString(resourceRequest, "chart_height");
		PrintWriter writer = resourceResponse.getWriter();
		resourceRequest.setCharacterEncoding("UTF-8");
		
		
		
		try {
			writer.print(VelocityTemplateUtil.getInstance().analysisTemplateToString(optionId,namespace,chart_view_theme,chart_height));
		} catch (PortalException e) {
			e.printStackTrace();
		} catch (SystemException e) {
			e.printStackTrace();
		}
		writer.flush();
		writer.close();
	}
}
